#include <iostream>
#include<cstring>
using namespace std;
class Student{
public:
    Student(const char* std_id,const char *name,int age)
        :_std_id(new char[strlen(std_id)+1]{})
        ,_name(new char[strlen(name)+1]{})
        ,_age(age){
            strcpy(_std_id,std_id);
            strcpy(_name,name);
            cout<<"student"<<endl;
        };
    void gets(){
        cout<<"id:"<<_std_id
            <<"name:"<<_name
            <<"age:"<<_age<<endl;
    }
    Student(const Student &st)
    :_std_id(new char[strlen(st._std_id)+1]{})
    ,_name(new char [strlen(st._name)+1]{})
    ,_age(st._age)
    {
        strcpy(_std_id,st._std_id);
        strcpy(_name,st._name);
        cout<<"copy"<<endl;
 
    }
    Student &operator=(const Student&st){
        //先清空原来的
        //
        if(_std_id){
            delete [] _std_id;
        }
        if(_name){
            delete [] _name;
        }
        _std_id = new char [strlen(st._std_id)+1]{};
        _name = new char [strlen(st._name)+1]{};
        strcpy(_std_id,st._std_id);
        strcpy(_name,st._name);
        _age = st._age;
        return *this;
    }
    ~Student(){
        if(_std_id){
            delete [] _std_id;
            _std_id = nullptr;
        }
        if(_name){
            delete [] _name;
            _name=nullptr;
        }
        cout<<"~Student"<<endl;
    }
private:
    char *_std_id;
    char *_name;
    int _age;
 
};
 
int main()
{
    Student std("1002","zs",19);
    std.gets();
    //复制
    Student s1 = std;
    s1.gets();
    //赋值
    Student s2("1003","kk",80);
    std = s2;
    std.gets();
    std::cout << "Hello world" << std::endl;
    return 0;
}
